<?php
/**
 * Defines some commen used functions
 * 
 * Defined the functions that were used continual, for redusing code amount
 * 
 * @author Zhang youlin
 * @version 1.0
 * @package Include
 */

function v($var) {
    var_dump($var);
}

function fielterMsg($msg) {
    return str_ireplace(Hero_Config::$limit_word, '', $msg);
}

function getip() {
    if(@$_SERVER['HTTP_X_FORWARDED_FOR']){
        $onlineip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        $c_agentip=1;
    } elseif(@$_SERVER['HTTP_CLIENT_IP']){
        $onlineip = $_SERVER['HTTP_CLIENT_IP'];
        $c_agentip=1;
    } else{
        $onlineip = $_SERVER['REMOTE_ADDR'];
        $c_agentip=0;
    }
    $onlineip = preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',$onlineip) ? $onlineip : 'Unknown'; 
    return $onlineip;
}

function set_msg($message, $type = 'msg') {
    $_SESSION['messages'][$type] = $message;
    $config = Registry::get('config');
    if ($config->bebo_enable or $config->yahoo_enable) { //yahoo and bebo  don't support session
        $fbuid = Registry::get('fbuid');
        if ($type == 'msg') {
            Setting::setVar($fbuid.'bebomsg', $message);
        } else {
            Setting::setVar($fbuid.'beboerror', $message);
        }
    }
}

function get_msg($type = 'msg') {
    $config = Registry::get('config');
    $fbuid = Registry::get('fbuid');
    if (isset($_SESSION['messages'][$type])) {
        $error = '<div class="'.$type.'">'.$_SESSION['messages'][$type].'</div>';
        unset($_SESSION['messages'][$type]);
        return $error;
    }
    
    if ($config->bebo_enable or $config->yahoo_enable) { //yahoo and bebo  don't support session
            if ($msg = Setting::getVar($fbuid.'bebo'.$type)) {
                $msg = '<div class="'.$type.'">'.$msg.'</div>';
                Setting::deleteVar($fbuid.'bebo'.$type, '');
                return $msg;
            }
        }
}


function redirect($url) {
	header("Location: " . $url);
	exit;
}

